package com.example.project22_editingmediaplayer.service;

import com.example.project22_editingmediaplayer.LayoutAllSong;
import com.example.project22_editingmediaplayer.MainActivity;
import com.example.project22_editingmediaplayer.R;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;

public class MediaReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		String action = intent.getStringExtra("action");
		if (action.equals("play")) {
			if (MainActivity.mService.getMediaPlayer() != null) {
				RemoteViews remoteViews;
				if (intent.getExtras() != null) {
					remoteViews = new RemoteViews(context.getPackageName(),
							R.layout.notification_custum);
					if (MainActivity.mService.getMediaPlayer().isPlaying()) {
						MainActivity.mService.getMediaPlayer().pause();
						remoteViews.setImageViewResource(R.id.btnPlayNoti,
								R.drawable.apollo_holo_light_play);
						Log.e("pause", "pause");
					} else {
						MainActivity.mService.getMediaPlayer().start();
						remoteViews.setImageViewResource(R.id.btnPlayNoti,
								R.drawable.apollo_holo_light_pause);
						Log.e("start", "start");
					}
					
				}
			}
			return;
		}
		if (action.equals("next")) {
			MainActivity.mService.nextSong(true);
			return;
		}

		if (action.equals("previus")) {
			MainActivity.mService.previusSong(true);
			return;
		}
	}

}
